import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from 'vuex-persist'
Vue.use(Vuex)
const vuexLocal = new VuexPersistence({
	storage: {
		getItem: key => uni.getStorageSync(key),
		setItem: (key, value) => uni.setStorageSync(key, value),
		removeItem: key => uni.removeStorageSync(key),
		clear: () => uni.clearStorageSync(),
	}
})

const store = new Vuex.Store({
	plugins: [vuexLocal.plugin],
	state: {
		hasLogin: false,
		userInfo:{}
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
		},
		logout(state, opts) {
			state.hasLogin = false
		}
	},
	actions: {
		actionLogin: ({ state, commit }, opts) => {
			commit('login', opts)
		}
	}
})

export default store
